﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Media3D;
using System.Linq;
using System.ComponentModel;
using TouchLibEvents;

namespace nl.tno.ict.multitouch.wpfmultitouch.controls
{
    public class MTProperties : DependencyObject
    {        
        

        #region CanBeScaled
        public static readonly DependencyProperty CanBeScaledProperty;
        /// <summary>
        /// Get the CanBeScaled property
        /// </summary>
        /// <param name="uiElement">The object</param>
        /// <returns>True/False</returns>
        public static bool GetCanBeScaled(UIElement uiElement)
        {
            if (uiElement == null)
                return false;

            return (bool)uiElement.GetValue(CanBeScaledProperty);
        }

        /// <summary>
        /// Set the CanBeScaled property
        /// </summary>
        /// <param name="uiElement"></param>
        /// <param name="value"></param>
        public static void SetCanBeScaled(UIElement uiElement, bool value)
        {
            if (uiElement != null)
                uiElement.SetValue(CanBeScaledProperty, value);
        }


        #endregion


        #region CanBeDragged

        public static readonly DependencyProperty CanBeDraggedProperty;
        /// <summary>
        /// Get the CanBeDragged property
        /// </summary>
        /// <param name="uiElement"></param>
        /// <returns></returns>
        public static bool GetCanBeDragged(UIElement uiElement)
        {
            if (uiElement == null)
                return false;

            return (bool)uiElement.GetValue(CanBeDraggedProperty);
        }
        /// <summary>
        /// Set the CanBeDragged property
        /// </summary>
        /// <param name="uiElement"></param>
        /// <param name="value"></param>
        public static void SetCanBeDragged(UIElement uiElement, bool value)
        {
            if (uiElement != null)
                uiElement.SetValue(CanBeDraggedProperty, value);
        }

        #endregion // CanBeDragged

        #region CanBeRotated
        public static readonly DependencyProperty CanBeRotatedProperty;
        /// <summary>
        /// Get the CanBeRotated property
        /// </summary>
        /// <param name="uiElement"></param>
        /// <returns></returns>
        public static bool GetCanBeRotated(UIElement uiElement)
        {
            if (uiElement == null)
                return false;

            return (bool)uiElement.GetValue(CanBeRotatedProperty);
        }
        /// <summary>
        /// Set the CanBeRotated property
        /// </summary>
        /// <param name="uiElement"></param>
        /// <param name="value"></param>
        public static void SetCanBeRotated(UIElement uiElement, bool value)
        {
            if (uiElement != null)
                uiElement.SetValue(CanBeRotatedProperty, value);
        }
        #endregion 
    
        #region TouchClick

        public static readonly DependencyProperty CanBeClickedProperty;

        /// <summary>
        /// Get the CanBeClicked property. Only used by object who implements the click event e.g MTButton
        /// </summary>
        /// <param name="uiElement"></param>
        /// <returns></returns>
        public static bool GetCanBeClicked(UIElement uiElement)
        {
            if (uiElement == null)
                return false;

            return (bool)uiElement.GetValue(CanBeClickedProperty);
        }

        /// <summary>
        /// Set the CanBeClicked property
        /// </summary>
        /// <param name="uiElement"></param>
        /// <param name="value"></param>
        public static void SetCanBeClicked(UIElement uiElement, bool value)
        {
            if (uiElement != null)
                uiElement.SetValue(CanBeClickedProperty, value);
        }

        #endregion

        #region TouchEnabled

        public static readonly DependencyProperty TouchEnabledProperty;

        /// <summary>
        /// Get the TouchEnabledProperty. This property is used to change the Z-index at touched objects.
        /// </summary>
        /// <param name="uiElement"></param>
        /// <returns></returns>
        public static bool GetTouchEnabled(UIElement uiElement)
        {
            if (uiElement == null)
                return false;

            return (bool)uiElement.GetValue(TouchEnabledProperty);
        }

        /// <summary>
        /// Set the TouchEnabledProperty. This property is used to change the Z-index at touched objects.
        /// </summary>
        /// <param name="uiElement"></param>
        /// <param name="value"></param>
        public static void SetTouchEnabled(UIElement uiElement, bool value)
        {
            if (uiElement != null)
                uiElement.SetValue(TouchEnabledProperty, value);
        }

        public static void SetTouchEnabled(UIElement uiElement, bool value, bool CanBeDragged, bool CanBeScaled, bool CanBeRotated)
        {
            if (uiElement != null)
            {
                uiElement.SetValue(TouchEnabledProperty, value);
                uiElement.SetValue(CanBeDraggedProperty, CanBeDragged);
                uiElement.SetValue(CanBeScaledProperty, CanBeScaled);
                uiElement.SetValue(CanBeRotatedProperty, CanBeRotated);
            }
        }

        #endregion

        #region AdornersEnabled
        public static readonly DependencyProperty AdornersEnabledProperty;

        /// <summary>
        /// Get the AdornerEnabled property. This property is used to show the Adorners.
        /// </summary>
        /// <param name="uiElement"></param>
        /// <returns></returns>
        public static bool GetAdornersEnabled(UIElement uiElement)
        {
            if (uiElement == null)
                return false;

            return (bool)uiElement.GetValue(AdornersEnabledProperty);
        }

        /// <summary>
        /// Set the AdornersEnabled property. This property is used to show the Adorners.
        /// </summary>
        /// <param name="uiElement"></param>
        /// <param name="value"></param>
        public static void SetAdornersEnabled(UIElement uiElement, bool value)
        {
            if (uiElement != null)
                uiElement.SetValue(AdornersEnabledProperty, value);
        }
        #endregion

        #region FingerAdornerEnabled
        public static readonly DependencyProperty FingerAdornerEnabledProperty;
        /// <summary>
        /// Not used...
        /// </summary>
        /// <param name="uiElement"></param>
        /// <returns></returns>
        public static bool GetFingerAdornerEnabled(UIElement uiElement)
        {
            if (uiElement == null)
                return false;

            return (bool)uiElement.GetValue(FingerAdornerEnabledProperty);
        }
        /// <summary>
        /// Not used...
        /// </summary>
        /// <param name="uiElement"></param>
        /// <param name="value"></param>
        public static void SetFingerAdornerEnabled(UIElement uiElement, bool value)
        {
            if (uiElement != null)
                uiElement.SetValue(FingerAdornerEnabledProperty, value);
        }
        #endregion

        #region AutoGeneratedKeyboardColor
        public static readonly DependencyProperty AutoGeneratedKeyboardColorProperty;
        /// <summary>
        /// Set AutoGeneratedKeyboardColor. This property set's an automatic color to the textbox and the keyboard.
        /// </summary>
        /// <param name="uiElement"></param>
        /// <returns></returns>
        public static bool GetAutoGeneratedKeyboardColor(UIElement uiElement)
        {
            if (uiElement == null)
                return false;

            return (bool)uiElement.GetValue(AutoGeneratedKeyboardColorProperty);
        }

        /// <summary>
        /// Get AutoGeneratedKeyboardColor. This property set's an automatic color to the textbox and the keyboard.
        /// </summary>
        /// <param name="uiElement"></param>
        /// <param name="value"></param>
        public static void SetAutoGeneratedKeyboardColor(UIElement uiElement, bool value)
        {
            if (uiElement != null)
                uiElement.SetValue(AutoGeneratedKeyboardColorProperty, value);
        }
        #endregion

        #region TouchManager

        /*public static readonly DependencyProperty TouchManagerProperty;

        public static TouchManager GetTouchManager(UIElement uiElement)
        {
            if (uiElement == null)
                return new TouchManager(uiElement, null);

            return (TouchManager)uiElement.GetValue(TouchManagerProperty);
        }

        public static void SetTouchManager(UIElement uiElement, TouchManager value)
        {
            if (uiElement != null)
                uiElement.SetValue(TouchManagerProperty, value);
        }*/


        #endregion
        
        #region IsScaling
        public static readonly DependencyProperty IsScalingProperty;
        /// <summary>
        /// Not used... (todo)
        /// </summary>
        /// <param name="uiElement"></param>
        /// <returns></returns>
        public static bool GetIsScaling(UIElement uiElement)
        {
            if (uiElement == null)
                return false;

            return (bool)uiElement.GetValue(IsScalingProperty);
        }

        /// <summary>
        /// Not used... (todo)
        /// </summary>
        /// <param name="uiElement"></param>
        /// <param name="value"></param>
        public static void SetIsScaling(UIElement uiElement, bool value)
        {
            if (uiElement != null)
                uiElement.SetValue(IsScalingProperty, value);
        }
        #endregion

        #region IsDragging
        /// <summary>
        /// Not used... (todo)
        /// </summary>
        public static readonly DependencyProperty IsDraggingProperty;

        public static bool GetIsDragging(UIElement uiElement)
        {
            if (uiElement == null)
                return false;

            return (bool)uiElement.GetValue(IsDraggingProperty);
        }

        /// <summary>
        /// Not used... (todo)
        /// </summary>
        /// <param name="uiElement"></param>
        /// <param name="value"></param>
        public static void SetIsDragging(UIElement uiElement, bool value)
        {
            if (uiElement != null)
                uiElement.SetValue(IsDraggingProperty, value);
        }
        #endregion 

        #region IsRotating

        public static readonly DependencyProperty IsRotatingProperty;

        /// <summary>
        /// Not used... (todo)
        /// </summary>
        /// <param name="uiElement"></param>
        /// <returns></returns>
        internal static bool GetIsRotating(UIElement uiElement)
        {
            if (uiElement == null)
                return false;
            return (bool)uiElement.GetValue(IsRotatingProperty);
        }


        /// <summary>
        /// Not used... (todo)
        /// </summary>
        /// <param name="uiElement"></param>
        /// <param name="value"></param>
        internal static void SetIsRotating(UIElement uiElement, bool value)
        {
            if (uiElement != null)
                uiElement.SetValue(IsRotatingProperty, value);
        }

        public static readonly DependencyProperty OnTopProperty;

        /// <summary>
        /// Set the OnTop property. This property is used to change the z-index when a finger touches an object.
        /// </summary>
        /// <param name="uiElement"></param>
        /// <param name="value"></param>
        public static void SetOnTop(UIElement uiElement, bool value)
        {
            if (uiElement != null)
                uiElement.SetValue(OnTopProperty, value);
        }

        /// <summary>
        /// Set the OnTop property. This property is used to change the z-index when a finger touches an object.
        /// </summary>
        /// <param name="uiElement"></param>
        /// <returns></returns>
        public static bool GetOnTop(UIElement uiElement)
        {
            if (uiElement == null)
                return false;
            return (bool)uiElement.GetValue(OnTopProperty);
        }
        #endregion


     
        #region Dependency Properties

         //public static readonly RoutedEvent MouseDoubleClickEvent;
        /* public static readonly RoutedEvent MouseEnterEvent;
         public static readonly RoutedEvent MouseLeaveEvent;
         public static readonly RoutedEvent MouseMoveEvent;
         public static readonly RoutedEvent MouseDownEvent;
         public static readonly RoutedEvent MouseUpEvent;
                 */
        #endregion // Dependency Properties

        /// <summary>
        /// Use this stacic class to make MTObjects. All of the MTEnabling methods are starting with SET or GET
        /// e.g. SetCanBeScaled();
        /// </summary>
        public MTProperties()
        {

        }
        /// <summary>
        /// Use this stacic class to make MTObjects. All of the MTEnabling methods are starting with SET or GET
        /// e.g. SetCanBeScaled();
        /// </summary>
        static MTProperties()
		{
            try
            {
                CanBeDraggedProperty = DependencyProperty.RegisterAttached(
                    "CanBeDragged",
                    typeof(bool),
                    typeof(MTCanvas),
                    new UIPropertyMetadata(false));

                CanBeScaledProperty = DependencyProperty.RegisterAttached(
                    "CanBeScaled",
                    typeof(bool),
                    typeof(MTCanvas),
                    new UIPropertyMetadata(false));

                CanBeClickedProperty = DependencyProperty.RegisterAttached(
                    "CanBeClicked",
                    typeof(bool),
                    typeof(MTCanvas),
                    new UIPropertyMetadata(false));

                TouchEnabledProperty = DependencyProperty.RegisterAttached(
                    "TouchEnabled",
                    typeof(bool),
                    typeof(MTCanvas),
                    new UIPropertyMetadata(false));

                CanBeRotatedProperty = DependencyProperty.RegisterAttached(
                    "CanBeRotated",
                    typeof(bool),
                    typeof(MTCanvas),
                    new UIPropertyMetadata(false));

                AdornersEnabledProperty = DependencyProperty.RegisterAttached(
                    "AdornersEnabled",
                    typeof(bool),
                    typeof(MTCanvas),
                    new UIPropertyMetadata(false));

                FingerAdornerEnabledProperty = DependencyProperty.RegisterAttached(
                    "FingerAdornerEnabled",
                    typeof(bool),
                    typeof(MTCanvas),
                    new UIPropertyMetadata(false));

                IsDraggingProperty = DependencyProperty.RegisterAttached(
                    "IsDragging",
                    typeof(bool),
                    typeof(MTCanvas),
                    new UIPropertyMetadata(false));

                IsScalingProperty = DependencyProperty.RegisterAttached(
                    "IsScaling",
                    typeof(bool),
                    typeof(MTCanvas),
                    new UIPropertyMetadata(false));

                IsRotatingProperty = DependencyProperty.RegisterAttached(
                    "IsRotating",
                    typeof(bool),
                    typeof(MTCanvas),
                    new UIPropertyMetadata(false));

                AutoGeneratedKeyboardColorProperty = DependencyProperty.RegisterAttached(
                    "AutoGeneratedKeyboardColor",
                    typeof(bool),
                    typeof(MTCanvas),
                    new UIPropertyMetadata(false));

                OnTopProperty = DependencyProperty.RegisterAttached(
                    "OnTop",
                    typeof(bool),
                    typeof(MTCanvas),
                    new UIPropertyMetadata(true));

                
            }
            catch
            {
            }
            

            /*FrameworkElement.MouseEnterEvent = EventManager.RegisterRoutedEvent("MouseEnterEvent",
            RoutingStrategy.Bubble, typeof(RoutedEvent), typeof(MTCanvas));*/

            /*FrameworkElement.MouseLeaveEvent = EventManager.RegisterRoutedEvent("MouseLeaveEvent",
            RoutingStrategy.Bubble, typeof(RoutedEvent), typeof(MTCanvas));

            FrameworkElement.MouseMoveEvent = EventManager.RegisterRoutedEvent("MouseMoveEvent",
            RoutingStrategy.Bubble, typeof(RoutedEvent), typeof(MTCanvas));

            FrameworkElement.MouseDownEvent = EventManager.RegisterRoutedEvent("MouseDownEvent",
            RoutingStrategy.Bubble, typeof(RoutedEvent), typeof(MTCanvas));

            FrameworkElement.MouseUpEvent = EventManager.RegisterRoutedEvent("MouseUpEvent",
            RoutingStrategy.Bubble, typeof(RoutedEvent), typeof(MTCanvas));
             */
            
            /*TouchManagerProperty = DependencyProperty.RegisterAttached(
                "TouchManager",
                typeof(TouchManager),
                typeof(MTCanvas),
                new UIPropertyMetadata());*/
		}/*
        public event RoutedEventHandler MouseDoubleClick
        {
            add { AddHandler(ObjectProperties.MouseDoubleClickEvent, value); }
            remove { RemoveHandler(ObjectProperties.MouseDoubleClickEvent, value); }
        }

        public event RoutedEventHandler MouseEnter
        {
            add { AddHandler(ObjectProperties.MouseEnterEvent, value); }
            remove { RemoveHandler(ObjectProperties.MouseEnterEvent, value); }
        }

        public event RoutedEventHandler MouseLeave
        {
            add { AddHandler(ObjectProperties.MouseLeaveEvent, value); }
            remove { RemoveHandler(ObjectProperties.MouseLeaveEvent, value); }
        }

        // A .NET event wrapper 
        public event RoutedEventHandler MouseMove
        {
            add { AddHandler(ObjectProperties.MouseMoveEvent, value); }
            remove { RemoveHandler(ObjectProperties.MouseMoveEvent, value); }
        }

        public event RoutedEventHandler MouseUp
        {
            add { AddHandler(ObjectProperties.MouseUpEvent, value); }
            remove { RemoveHandler(ObjectProperties.MouseUpEvent, value); }
        }

        public event RoutedEventHandler MouseDown
        {
            add { AddHandler(ObjectProperties.MouseDownEvent, value); }
            remove { RemoveHandler(ObjectProperties.MouseDownEvent, value); }
        }*/
    }
}
